package com.fox.service.impl;

import com.fox.mapper.UserMapper;
import com.fox.pojo.User;
import com.fox.service.UserService;
import com.fox.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByUserName(String userName) {
        User user = userMapper.findByUserName(userName);
        return user;
    }

    @Override
    public void register(String username, String password) {
        String md5String = Md5Util.getMD5String(password);
        userMapper.add(username, md5String);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void updateAvatar(String avatarUrl, Integer id) {
        userMapper.updateAvatar(avatarUrl, id);
    }

    @Override
    public void updatePassword(String password, Integer id) {
        String md5String = Md5Util.getMD5String(password);
        userMapper.updatePassword(md5String, id);
    }
}
